/**
 * 
 * url: https://101.zoo.team/shu-xue/shu-xue-part-1-luo-ma-shu-zi-zhuan-zheng-shu-fizz-buzz-he-ji-shu-zhi-shu#fizz-buzz
 * 
 * LeetCode： https://leetcode-cn.com/problems/fizz-buzz/
 * 
 * n = 15,
 * 返回:
 * [
    "1",
    "2",
    "Fizz",
    "4",
    "Buzz",
    "Fizz",
    "7",
    "8",
    "Fizz",
    "Buzz",
    "11",
    "Fizz",
    "13",
    "14",
    "FizzBuzz"
 * ]
 * 
 */

/**
 * 遍历
 */
const fizzBuzz1 = (num) => {
    let res = []
    for (let i = 1 ;  i <= num ; i++) {
        // 被3 和 5整除，即15
        if (i % 15 === 0) {
            res.push('FizzBuzz')
        }
        // 被3整除
        else if (i % 3 === 0) {
            res.push('Fizz')
        } 
        // 被5整除
        else if (i % 5 === 0) {
            res.push('Buzz')
        }
        // 都不是输出本身
        else {
            res.push(''+i)
        }
    }
    return res
}

/**
 * 字符串累加
 */
const fizzBuzz2 = (num) => {
    let res = []
    for (let i = 1; i <= num; i++) {
        res[i-1] = ''
        // 被 3 整除
        if (i % 3 === 0) {
            res[i-1] += 'Fizz'
        } 
        // 被 5 整除
        if (i % 5 === 0) {
            res[i-1] += 'Buzz'
        }
        // 其他
        if (i % 3 !== 0 && i % 5 !== 0) {
            res[i-1] += i
        }
    }
    
    return res
}
